package easy;

public class Solution_999 {

    public int numRookCaptures(char[][] board) {
        int r = 0, c = 0;
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board.length; j++) {
                if (board[i][j] == 'R') {
                    r = i;
                    c = j;
                    break;
                }
            }
        }
        int count = 0;
        for (int i = c + 1; i < board.length; i++) {
            if (board[r][i] == 'p') {
                count++;
                break;
            } else if (board[r][i] == 'P' || board[r][i] == 'B' || board[r][i] == 'b' || board[r][i] == 'r') {
                break;
            }
        }

        for (int i = c - 1; i >= 0; i--) {
            if (board[r][i] == 'p') {
                count++;
                break;
            } else if (board[r][i] == 'P' || board[r][i] == 'B' || board[r][i] == 'b' || board[r][i] == 'r') {
                break;
            }
        }

        for (int i = r + 1; i < board.length; i++) {
            if (board[i][c] == 'p') {
                count++;
                break;
            } else if (board[i][c] == 'P' || board[i][c] == 'B' || board[i][c] == 'b' || board[i][c] == 'r') {
                break;
            }
        }

        for (int i = r - 1; i >= 0; i--) {
            if (board[i][c] == 'p') {
                count++;
                break;
            } else if (board[i][c] == 'P' || board[i][c] == 'B' || board[i][c] == 'b' || board[i][c] == 'r') {
                break;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Solution_999 model = new Solution_999();
        System.out.println(model.numRookCaptures(new char[][]{
        {'.','.','.','.','.','.','p','.'},
        {'p','.','.','.','.','.','R','.'},
        {'.','.','.','.','.','.','.','.'},
        {'.','.','.','.','.','.','.','.'},
        {'.','.','.','.','.','.','.','.'},
        {'.','.','.','.','.','.','.','.'},
        {'.','.','.','.','.','.','.','.'},
        {'.','.','.','.','.','.','p','.'}}));
    }
}
